package xin.marcher.module.quality.cor.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xin.marcher.module.quality.cor.RiskHandler;
import xin.marcher.module.quality.domain.dto.ItemQualityControlResultDTO;
import xin.marcher.module.quality.domain.entity.ItemQualityControlDataDO;
import xin.marcher.module.quality.repository.ItemQualityControlRepository;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 */
@Component
public class RiskDataHandler implements RiskHandler {

    @Autowired
    private ItemQualityControlRepository itemQualityControlRepository;

    /**
     * 处理风险商品列表中已存在的风险数据
     *
     * @param riskDataMap
     * @return
     */
    @Override
    public Map<String, ItemQualityControlResultDTO> handle(Map<String, ItemQualityControlResultDTO> riskDataMap) {
        // 风险ID集合
        Set<String> surveyIdSet = riskDataMap.keySet();
        // 已存在的风险数据
        List<ItemQualityControlDataDO> existsInRiskResultDataList = itemQualityControlRepository.queryExistsInRiskResultData(surveyIdSet);
        // 更新风险等级，剔除掉存在的风险数据
        itemQualityControlRepository.updateExistsInRiskResultData(riskDataMap, existsInRiskResultDataList);
        return riskDataMap;
    }
}
